import {
  getTemp, getHistory, getChangeRate, getQinshiResult,getRadarDataIn,getRadarDataOut,
  getQinshiHistory, getAvgStatus, getActivinessPredictLong,getActivinessPredictShort
} from '@/services/lugang';

const initState = {
  temp: [],
  history: {
    current: null,
    histories: [],
    changeRate: {group:[],recommend:[]}
  },
  avgStatus: {
    data: [],
    zhou_avg: '',
    jing_avg: '',
  },
  activinessPredictLong: {
    current: [],
    predict: []
  },
  activinessPredictShort: {
    current: [],
    predict: []
  },
  qinshiResult:{
    group1: [],
    group2: []
  }
};

const Lugang = {
  namespace: 'lugang',
  state: initState,
  effects: {
    //异步方法,应该通常用于前后端交互
    * getTemp({payload}, {call, put}) {
      const response = yield call(getTemp, payload);
      // dispatch转发action
      yield put({
        type: 'saveValues',
        payload: response.detail,
        name: "temp",
      });
    },

    * getHistory({payload}, {call, put}) {
      const response = yield call(getHistory, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "history"
      })
    },
    * getChangeRate({payload}, {call, put}) {
      const response = yield call(getChangeRate, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "changeRate"
      })
    },

    * getQinshiResult({payload}, {call, put}) {
      const response = yield call(getQinshiResult, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "qinshiResult"
      })
    },

    * getQinshiHistory({payload}, {call, put}) {
      const response = yield call(getQinshiHistory, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "qinshiHistory"
      })
    },

    * getAvgStatus({payload}, {call, put}) {
      const response = yield call(getAvgStatus, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "avgStatus"
      })
    },
    * getActivinessPredictLong({payload}, {call, put}) {
      const response = yield call(getActivinessPredictLong, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "activinessPredictLong"
      })
    },

    * getActivinessPredictShort({payload}, {call, put}) {
      const response = yield call(getActivinessPredictShort, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "activinessPredictShort"
      })
    },
    * getRadarDataIn({payload}, {call, put}) {
      const response = yield call(getRadarDataIn, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "radarDataIn"
      })
    },
    * getRadarDataOut({payload}, {call, put}) {
      const response = yield call(getRadarDataOut, payload);
      yield  put({
        type: 'saveValues',
        payload: response.detail,
        name: "radarDataOut"
      })
    },

  },
  reducers: {
    saveValues(state, {payload, name}) {
      const v = {...state};
      v[name] = payload;
      return v
    },
  },
};
export default Lugang;
